package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 考试模式枚举
 */
public enum ExamMode implements BaseEnum {

    /**
     * 在线考试
     */
    ONLINE("ONLINE", "在线考试"),

    /**
     * 线下考试
     */
    OFFLINE("OFFLINE", "线下考试"),

    /**
     * 混合模式
     */
    HYBRID("HYBRID", "混合模式"),

    /**
     * 监考模式
     */
    PROCTORED("PROCTORED", "监考模式"),

    /**
     * 开卷考试
     */
    OPEN_BOOK("OPEN_BOOK", "开卷考试"),

    /**
     * 闭卷考试
     */
    CLOSED_BOOK("CLOSED_BOOK", "闭卷考试");

    private final String code;
    private final String description;

    ExamMode(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     */
    public static ExamMode fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return ONLINE;
        }

        for (ExamMode mode : values()) {
            if (mode.getCode().equals(code)) {
                return mode;
            }
        }
        return ONLINE;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}